<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input
      type="text"
      value="Count to 20, with a comma between each number and no newlines. E.g., 1, 2, 3, ..."
    />
    <button>发送</button>
    <script>
      const btn = document.querySelector('button');
      const inp = document.querySelector('input');
      async function sendMsg() {
        const resp = await fetch('http://localhost:7010/chat', {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
          },
          body: JSON.stringify({
            content: inp.value,
          }),
        });
        const reader = resp.body.getReader();
        const decoder = new TextDecoder();
        for (;;) {
          const { value, done } = await reader.read();
          if (done) {
            break;
          }
          const text = decoder.decode(value);
          console.log(text);
        }
      }

      btn.onclick = function () {
        sendMsg();
      };
    </script>
  </body>
</html>
